<?php
/**
 * Minhlog 日志存档边栏视图助手
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @category   View_Helper
 * @package    Minh_View_Helper
 * @copyright  Copyright (c) 2009-2010 Minh.Shu Minh.Shu@gmail.com
 * @license    New BSD License
 * @author     Minh.Shu
 * @version    $Id: ArchiveSideBar.php 32 2010-03-30 12:40:08Z minh.shu $
 * @uses        Zend_View_Helper
 */

class Minh_View_Helper_ArchiveSideBar extends Minh_View_Helper_SideBarAbstract
{
    public function archiveSideBar ()
    {
        $cacheId = md5('archiveSideBar');
        if (! ($archiveSideBarCache = $this->cache->load($cacheId))) {
            $archiveSideBar = array();

            $articleModel = new Domain_Model_Article();
            $resultSet = $articleModel->getAllArticle();
            if(null !== $resultSet){
                $archiveSideBar = array();
                foreach($resultSet as $result)
                {
                    $archive = new stdClass();
                    $archive->publishDate = date('Y/m',$result->article->publishTime);
                    $date = explode('/', $archive->publishDate);
                    $archive->dateString = sprintf('%s年%s月', $date[0], $date[1]);
                    if(!in_array($archive, $archiveSideBar)) $archiveSideBar[] = $archive;
                }
            } else {
                $this->cache->save($archiveSideBar, $cacheId);
            }
        } else {
            $archiveSideBar = $archiveSideBarCache;
        }
        return $archiveSideBar;
    }
}